package top.suven.base.core.db;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by joven on 16/8/30.
 * 封装每个项目的数据源对象；
 */
public class DataSourceGroup {

    private String groupName; //缓存对应的数据组
    private String masterSources; //master key
    private List<String> slaveSources = new ArrayList<>(); //slave集合信息
    private DataSourceEnum dataType = DataSourceEnum.MASTER; // 使用数据库类型: MASTER 或 SLAVE;
    private String dataClient; //当前数据库的值

    public DataSourceGroup(){}


    public DataSourceGroup(String groupName, DataSourceEnum dataType) {
        if(null != groupName){
            this.groupName = groupName;
        }
        if(dataType != null)
        this.dataType = dataType;
    }

    public String getMasterSources() {
        return masterSources;
    }

    public void setMasterSources(String masterSources) {
        this.masterSources = masterSources;
    }

    public List<String> getSlaveSources() {
        return slaveSources;
    }

    public void setSlaveSources(List<String> slaveSources) {
        this.slaveSources = slaveSources;
    }

    public void setSlaveSources(String slaveKey) {
        if(this.slaveSources == null){
            slaveSources = new ArrayList<>();
        }
        this.slaveSources.add(slaveKey);
    }


    public String getGroupName() {
        return groupName;
    }

    public DataSourceGroup setGroupName(String groupName) {
        this.groupName = groupName;
        return this;
    }

    public DataSourceEnum getDataType() {
        if(dataType == null){
            dataType = DataSourceEnum.MASTER;
        }
        return dataType;
    }

    public DataSourceGroup setDataType(DataSourceEnum dataType) {
        if(null != dataType){
            this.dataType = dataType;
        }
        return this;
    }

    public String getDataClient() {
        return dataClient;
    }

    public void setDataClient(String dataClient) {
        this.dataClient = dataClient;
    }
}
